#
# -*- coding: utf-8 -*-

from plurk import *
import plurk_api_urllib2
#import plurk_api
import datetime
import sys
try:
  import simplejson as json
except ImportError:
  print 'pyplurk requires simplejson module which can be found on http://www.undefined.org/python/.'
  sys.exit(1)
import mox

def example():
  api = plurk_api_urllib2.PlurkAPI(open('api.key').read().strip(), debug_level=1)
  #the_mox = mox.Mox()
  #api = the_mox.CreateMock(plurk_api.PlurkAPI)
  #api('/Users/login', True, username=self.username, 
  #           password=self.password).AndReturn(
  #print connection._cookies
  plurk = PlurkProxy(api, json.loads)
  user = plurk.Login('pingooo', 'xyz123')
  return
  rl = plurk.GetResponses(187638755, 0)
  print rl
  return
  username, password = open('testdata/test_account.dat').read().strip().split('\n')
  user = plurk.Login(username, password)
  print user if user != None else plurk.GetErrorText()
  if user:
    #result = plurk.UpdateUserInfo(password, display_name="Hello Plurk!")
    #result = plurk.GetPlurks(datetime.datetime(2009, 12, 12, 0, 0, 0))
    result = plurk.GetNewPlurks(since=datetime.datetime(2009,12,23))
    print result
    #if result:
    #  print 'user:', result['user']
    #else:
    #  print '%s: (%s,%s)' % (plurk.GetStatusCode(), plurk.GetResult(), plurk.GetErrorText())
    #print 'plurks:'
    #for p in result['plurks']:
    #  print p

  #print data1
  #print connection._cookies
  #data2 = plurk.GetPublicProfile('pyplurk')
  #print data2.plurks
  #print 'cookiejar =', plurk._conn._cookies
  #for x in plurk._conn._cookies:
  #  print 'cookie: {%s} = {%s}' % (x.name, x.value)
  #data2 = plurk.UpdateUserInfo('xyz123', 
  #                             date_of_birth=datetime.date(1991,3,10))
  #data2 = plurk.GetOwnProfile()
  #data2 = plurk.GetPlurks(datetime.datetime(2009, 2, 1))
  #print data2
  
  #plurk.Login('pyplurk', 'yyy')
  #uinfo = UserInfo('pingooo', PlurkProxy(PlurkConnection(open('api.key').read().strip())))
  #uinfo = UserInfo('pingooo', MockPlurkProxy('test/pingooo_nologin.html'))
  #uinfo = UserInfo('pingooo', MockPlurkProxy('test/wrong_format.html'))
  #print 'settings =\n', PrettyFormatDict(uinfo._settings)
  #print 'friends =\n', PrettyFormatDict(uinfo._friends)
  #print 'fans =\n', PrettyFormatDict(uinfo._fans)
  #print 'metadata =\n', PrettyFormatDict(uinfo._metadata)
  #print 'about =\n', PrettyFormatDict(uinfo._about)

if __name__ == '__main__':
  example()
